package com.iogogogo.activity.context;

import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

/**
 * Created by tao.zeng on 2022/6/16.
 */
public class ActivityRecordContext {

    private final static InheritableThreadLocal<Stack<Map<String, Object>>> VARIABLE_MAP_STACK = new InheritableThreadLocal<>();

    private final static Stack<Map<String, Object>> STACK_CONTAINER = new Stack<>();

    public static void putVariable(String key, Object value) {
        Map<String, Object> map = new HashMap<>();
        map.put(key, value);
        STACK_CONTAINER.push(map);
        VARIABLE_MAP_STACK.set(STACK_CONTAINER);
    }

    public static void putEmptySpan() {
    }

    public static Map<String, Object> getVariables() {
        Stack<Map<String, Object>> stack = VARIABLE_MAP_STACK.get();
        return stack.pop();
    }

    public static void clear() {
        VARIABLE_MAP_STACK.remove();
    }
}
